<?php
	require_once("../../../include/connect.php");
	require_once("../../../include/excel_reader2.php");
	
	$type = $_FILES["files"]["type"];	
	if($type != "application/vnd.ms-excel")
	{
		echo "Not type";
		//header("Location:../canbo.php?import=f#msg_import");
	}
	else
	{
		if ( $_FILES['files']['error'] > 0)
			echo "File error ! not found";
//			header("Location:../canbo.php?import=e#msg_import");
		else
		{
			$filename = $_FILES['files']['tmp_name'];
	
			if ( !is_file( $filename ) )
				//
			{
				exit('File not found.');
				//header("Location:_import_success.php?content=ie");
			}
	
			$data = new Spreadsheet_Excel_Reader($filename,true,"UTF-8");
			
			$rowsnum = $data->rowcount($sheet_index=0); 
			$colsnum = $data->colcount($sheet_index=0); 
			
			for ($i=7; $i<=$rowsnum; $i++)
			{
				$name = $data->val($i,2);
				$date_begin = date("Y-m-d",strtotime($data->val($i,3)));
				$date_end = date("Y-m-d",strtotime($data->val($i,4)));
					
				$res = mysql_fetch_array(mysql_query(" SELECT count(id) as cnt FROM course WHERE date_begin = '$date_begin' AND date_end = '$date_end' "));
				if($res['cnt'] == 0)
					$query = mysql_query(" INSERT INTO course(name,date_begin,date_end)
									VALUES (N'$name', '$date_begin', '$date_end') ");
			}
			header("Location:../index.php?p=course&msg=upload_success#tb");

		}
	}
	
?>